package xyz.syyrjx.registry.load;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import xyz.syyrjx.entity.SyyrjxRpcRemoteAddress;
import xyz.syyrjx.registry.conf.SyyrjxRpcRegistryConfiguration;

/**
 * @author 大地崩坏苍蝇兽
 * @date 2023/1/19 - 18:34
 */
public class SyyrjxRpcRegistryEnvironmentSetAware{

    public static void environmentInit(ApplicationContext applicationContext) throws BeansException {
        SyyrjxRpcRegistryConfiguration configuration = applicationContext.getBean(SyyrjxRpcRegistryConfiguration.class);

        //设置本机地址
        SyyrjxRpcRemoteAddress local = new SyyrjxRpcRemoteAddress();
        local.setHost(configuration.getHost());
        local.setPort(configuration.getPort());
        SyyrjxRpcRegistryConfiguration.setLocal(local);

        //设置配置类
        SyyrjxRpcRegistryConfiguration.setConfiguration(configuration);
    }
}
